/******************************************
 * Author: Dave Spadea, Spadea Enterprises, Inc.
 * Date: November 2010
 * 
 * This code is released by Spadea Enterprises, Inc for general consumption 
 * under the Apache Software License.
 * 
 */

package net.spadea.framework.persistence;

import java.sql.*;
import java.util.Hashtable;
import java.util.Properties;

public class Database {

	public static Connection getNewConnection() throws SQLException, ClassNotFoundException {
		Class.forName("org.postgresql.Driver");
		
		String url = System.getenv("FRAMEWORK_JDBC_CONNECT_STRING");
		Properties props = new Properties();
		Connection conn = DriverManager.getConnection(url, props);

		return conn;
		
	}
	
	public static Hashtable<String, Object> toHashtable(ResultSet rs) throws SQLException {
		Hashtable row = new Hashtable<String, Object>();
		
		ResultSetMetaData md = rs.getMetaData();
		for (int x = 1; x <= md.getColumnCount(); x++) {
			row.put(md.getColumnLabel(x), rs.getString(x));
		}
		
		return row;
	}
	
}
